jQuery(function($){
	jQuery("#datagrid").jqGrid({
	    url:'listPost.action',  
	    mtype: "POST",
	    datatype: "json",
	    colNames:['岗位名称', '所属部门', '创建日期', '修改日期'],
	    colModel:[
            {name:'post_name',index:'post_name',align:'center'},
	        {name:'department_name',index:'department_name'},
	        {name:'create_time',index:'create_time',datefmt:'Y-m-d',width:100},
	        {name:'modify_time',index:'modify_time',datefmt:'Y-m-d',width:100}	
	    ],
	    jsonReader: {
	    	root: "results",
	    	total: "totalpages",
	    	page: "currpage",
	    	records: "totalrecords",
	    	repeatitems: false
	    },
	    pager: '#pager',
	    rowNum:10,
	    rowList:[10,20,30],
	    sortname: 'post_id',
	    multiselect: true,
	    viewrecords: true,
	    sortorder: "ASC",
	    caption: "岗位列表",
	    autowidth: true,
	    height: '100%',
	    ondblClickRow: function(id, ri, ci, e){
			//var ptr = $(e.target, this.rows).closest("tr.jqgrow");
			//var user_code = ptr.attr("cells")[1].innerHTML;
			//loadUser(user_code);
	    	loadPost(id);
	    }
	});
	
	jQuery("#datagrid").navGrid(
		'#page',
		{add:false, edit:false, del:true, search:false, refresh:true},
		{},{},
		{
			modal:true,url:"deletePost.action",
			afterSubmit:function(data, params){
				if(data.responseText) {
					var obj = eval('('+ data.responseText +')');
					var msg = obj.message?obj.message:((obj.success==true || obj.success=='true')?"岗位信息删除成功！":"岗位信息删除失败！");
					return [obj.success, msg];
				} else {
					return [true];
				}
			}
		},{},{}
	);
});

function loadPost(post_id) {
	showMDialog('loadPost.action?edit=true&post.post_id='+post_id,'dialogWidth=900px;dialogHeight=600px');
//	window.open('loadPost.action?edit=true&post.post_id='+post_id);
}

function gridReload(){
//	var user_code = jQuery("#search_user_code").val(); 
//	var department_name = jQuery("#search_department_name").val();
//	jQuery("#datagrid").jqGrid('setGridParam',{url:"listPost.action?user.valid_flag=1",postData:{"user.user_code":user_code,"user.department_name":department_name},page:1}).trigger("reloadGrid");
	jQuery("#datagrid").trigger("reloadGrid");
}